home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1114 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: uu4news.netcom.com!zodiac!szh
  3. From: szh@zcon.com (Syed Zaeem Hosain)
  4. Subject: Re: Bit Masking
  5. Message-ID: <1996Jan11.133059.7153@zcon.com>
  6. Sender: szh@zcon.com (Syed Zaeem Hosain)
  7. Nntp-Posting-Host: zodiac
  8. Reply-To: szh@zcon.com
  9. Organization: Z Consulting Group
  10. References: <DKz5y4.8En@twisto.eng.hou.compaq.com>
  11. Date: Thu, 11 Jan 1996 13:30:59 GMT
  12.  
  13. In article <DKz5y4.8En@twisto.eng.hou.compaq.com>, garyc%cs%contractors@bangate.compaq.com (Gary Clarke) writes:
  14. >Can someone tell me the elegent way to clear specific bits from a
  15. >byte, e.g.
  16. >
  17. ># define BIT_1    1
  18. ># define BIT_2    2
  19. ># define BIT_3    4
  20. ># define BIT_4    8
  21. >
  22. >Set the bit:    x |= BIT_x
  23. >
  24. >Clear the bit using BIT_x:    ????
  25.  
  26. The following:
  27.  
  28.     x &= ~BIT_x;
  29.  
  30. will clear the bit. But be careful to use unsigned variables to avoid
  31. surprises with sign bits!    :-)
  32.  
  33.                                 Z
  34.  
  35.  
  36. -- 
  37. -------------------------------------------------------------------------
  38. | Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |
  39. | Z Consulting Group        San Jose, CA 95161             szh@zcon.com |
  40. -------------------------------------------------------------------------
  41.